﻿using System;
using System.IO;

using SharpOSCAR.Base;

namespace SharpOSCAR.Snac.OSERVICE
{
    /// <summary>
    /// Description of a foodgroup and the version of that foodgroup the client wants
    /// to use when communicating with the backend.
    /// </summary>
    public class OSERVICE__Version : ProtocolData
    {
        private U16 _Foodgroup;
        private U16 _Version;
        private U16 _ToolID;
        private U16 _ToolVersion;

        /// <summary>
        /// Initialzes the OSERVICE__Version SNAC
        /// </summary>    
        /// <param name="foodgroup">Foodgroup that the version represents</param>
        /// <param name="version">Version of the foodgroup implementation; should be 4 for OSERVICE, 3 for FEEDBAG, 1 for all others</param>
        public OSERVICE__Version(SNAC__FOODGROUPS foodgroup, ushort version)
        {
            _Foodgroup = new U16((ushort)foodgroup);
            _Version = new U16(version);
            _ToolID = new U16(41);
            _ToolVersion = new U16(1);
        }

        /// <summary>
        /// Converts the SNAC into a byte array
        /// </summary>
        /// <returns>Returns a byte array representing the SNAC</returns>
        public override byte[] ToByteArray()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                _Foodgroup.WriteToStream(ms);
                _Version.WriteToStream(ms);
                _ToolID.WriteToStream(ms);
                _ToolVersion.WriteToStream(ms);
                return ms.ToArray();
            }
        }
    }
}
